<template>
  <div class="app-container">
    <div class="content-box">
      <el-form
        v-show="showSearch"
        ref="queryForm"
        :model="queryParams"
        :inline="true"
        label-width="68px"
      >
        <el-form-item label="标题" prop="title">
          <el-input
            v-model="queryParams.title"
            placeholder="请输入标题"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="操作人" prop="username">
          <el-input
            v-model="queryParams.username"
            placeholder="请输入操作人"
            clearable
            size="small"
            style="width: 240px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="betimearr">
          <el-date-picker
            v-model="queryParams.betimearr"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索</el-button>
          <el-button
            icon="el-icon-refresh"
            size="mini"
            @click="resetQuery"
          >重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            v-hasPermi="['log:del']"
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
          >删除</el-button>
        </el-col>
        <right-toolbar
          show-search-sync="true"
          @queryTable="getList"
        />
      </el-row>

      <el-table
        v-loading="loading"
        :data="list"
        row-key="id"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="50" align="center" />
        <el-table-column prop="id" label="ID" width="50" />
        <el-table-column prop="username" label="用户名" align="center" />
        <el-table-column prop="title" label="标题" align="center" />
        <el-table-column prop="url" label="地址" align="center" />
        <el-table-column prop="content" label="内容" align="center" />
        <el-table-column prop="ip" label="IP" align="center" />
        <el-table-column prop="createtime" label="创建时间" align="center" />
        <!-- <el-table-column label="操作" align="center" class-name="small-padding">
          <template slot-scope="scope">
            <el-col :span="1.5">
              <el-button
                v-hasPermi="['log:info']"
                type="text"
                icon="el-icon-info"
                size="mini"
                @click="handleInfo(scope.row)"
              >详情</el-button>
            </el-col>
            <el-button
              v-hasPermi="['log:del']"
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>-->
      </el-table> 
      <pagination
        v-show="totalSize > 0"
        :total="totalSize"
        :page.sync="queryParams.page"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 详情对话框 -->
      <el-dialog
        :title="title"
        :visible.sync="open"
        width="600px"
        append-to-body
      >
        <el-form ref="form" :model="form" label-width="80px">
          <el-row>
            <el-col :span="24">
              <el-form-item label="ID">
                {{ form.id }}
              </el-form-item>
              <el-form-item label="用户名">
                {{ form.username }}
              </el-form-item>
              <el-form-item label="标题">
                {{ form.title }}
              </el-form-item>
              <el-form-item label="地址">
                {{ form.url }}
              </el-form-item>
              <el-form-item label="内容">
                {{ form.content }}
              </el-form-item>
              <el-form-item label="IP">
                {{ form.ip }}
              </el-form-item>
              <el-form-item label="创建时间">
                {{ form.createtime }}
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import {getList } from '@/api/operationLog'

export default {
  name: 'LogIndex',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 数据
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 显示状态数据字典
      visibleOptions: [],
      // 菜单状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        title: '',
        username: '',
        betimearr: [],
        betime: '',
        page: 1,
        pageSize: 10
      },
      totalSize: 1,
      // 非多个禁用
      multiple: true,
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  watch: {
    'queryParams.betimearr'(value) {
      this.queryParams.start_createtime = value[0]
      this.queryParams.end_createtime = value[1]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = false
      getList(this.queryParams).then((response) => {
        this.list = response.data.list
        this.totalSize = response.data.total_page
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {}
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm('是否确认删除ID为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return delConfig(ids)
        })
        .then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        })
    },
    handleInfo(row) {
      this.reset()
      infoLog(row.id).then((response) => {
        this.form = response.data
        this.open = true
        this.title = '详情'
      })
    }
  }
}
</script>
